//
//  HomeViewController.swift
//  ExtremeHealth
//
//  Created by Zhongkai Li 李忠凯 on 2018/8/22.
//  Copyright © 2018 GanDongKeJi. All rights reserved.
//

import Eureka

class HomeViewController: EHBaseFormViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        setupNavibar()
    }

    override func setupRows() {
        let headerRow = EHImageViewRow { row in
            row.configuration = generateImageViewConfiguration()
        }
        addRow(headerRow)

        var titleRow = EHTitleRow { row in
            row.configuration = generateTitleConfiguration(with: "饮食 & 运动记录")
        }
        addRow(titleRow)

        addSeperatorLineRow(withMargins: .init(top: 20, left: 80, bottom: 20, right: 0))

        titleRow = EHTitleRow { row in
            row.configuration = generateTitleConfiguration(with: "健康习惯")
        }
        addRow(titleRow)

        addSeperatorLineRow(withMargins: .init(top: 20, left: 80, bottom: 20, right: 0))

        titleRow = EHTitleRow { row in
            row.configuration = generateTitleConfiguration(with: "运动训练")
        }
        addRow(titleRow)

        addSeperatorLineRow(withMargins: .init(top: 20, left: 80, bottom: 20, right: 0))

        titleRow = EHTitleRow { row in
            row.configuration = generateTitleConfiguration(with: "步数记录")
        }
        addRow(titleRow)
    }

    private func generateTitleConfiguration(with title: String) -> EHTitleRowConfiguration {
        return EHTitleRowConfiguration()
                .setImage(UIImage(named: "navigationbar_btn_close"))
                .setTitle(title)
                .setAction {
                    debugPrint("sdfsdf")
                }
    }

    private func generateImageViewConfiguration() -> EHImageViewConfiguration {
        return EHImageViewConfiguration()
                .setImage(UIImage(named: "chrysanthemum")!)
    }

    private func setupNavibar() {
        navigationController?.navigationBar.shadowImage = UIImage()
        navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
        navigationController?.view.backgroundColor = .clear
        navigationController?.navigationBar.backgroundColor = UIColor.clear

        let imageView = UIImageView(image: UIImage(named: "navigationbar_btn_close"))
        imageView.translatesAutoresizingMaskIntoConstraints = false
        navigationController?.navigationBar.addSubview(imageView)
        let vvv = navigationController!.navigationBar
        NSLayoutConstraint.activate([
            imageView.centerYAnchor.constraint(equalTo: vvv.centerYAnchor),
            imageView.widthAnchor.constraint(equalToConstant: 30),
            imageView.heightAnchor.constraint(equalToConstant: 30),
            imageView.rightAnchor.constraint(equalTo: vvv.rightAnchor, constant: -15)
            ])
    }

}
